package com.iwinding.ladygg.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.iwinding.ladygg.constant.SPConstant;

/**
 * Created by Administrator on 2016/8/24.
 */
public class SPUtils {

    public static void putSpProperty(Context mContext, String name, Object property) {
        SharedPreferences.Editor editor = mContext.getSharedPreferences(SPConstant.APP_SPNAME, Context.MODE_APPEND).edit();
        if (property instanceof String)
            editor.putString(name, (String) property);
        if (property instanceof Boolean)
            editor.putBoolean(name, (Boolean) property);
        if (property instanceof Integer)
            editor.putInt(name, (Integer) property);
        if (property instanceof Long)
            editor.putLong(name, (Long) property);
        editor.commit();
        editor.clear();
    }

    public static String getSpPropertyString(Context mContext, String name, String defaultStr) {
        SharedPreferences sp = mContext.getSharedPreferences(SPConstant.APP_SPNAME, Context.MODE_APPEND);
        return sp.getString(name, defaultStr);
    }

    public static Boolean getSpPropertyBoolean(Context mContext, String name, Boolean defaultBool) {
        SharedPreferences sp = mContext.getSharedPreferences(SPConstant.APP_SPNAME, Context.MODE_APPEND);
        return sp.getBoolean(name, defaultBool);
    }

    public static Integer getSpPropertyInt(Context mContext, String name, int defaultStr) {
        SharedPreferences sp = mContext.getSharedPreferences(SPConstant.APP_SPNAME, Context.MODE_APPEND);
        return sp.getInt(name, defaultStr);
    }

    public static Long getSpPropertyLong(Context mContext, String name, long defaultStr) {
        SharedPreferences sp = mContext.getSharedPreferences(SPConstant.APP_SPNAME, Context.MODE_APPEND);
        return sp.getLong(name, defaultStr);
    }

    public static String getToken(Context mContext) {
        return SPUtils.getSpPropertyString(mContext, SPConstant.TOKEN_STR, "");
    }

}
